# # 1. 有以下二维列表，编写算法求列表中是否存在鞍点。若有，请编程求出。（MT-I）
# arr = [
#     [10 , 14 ,  9 ,  15],
#     [7  , 4 ,  8 ,  10 ],
#     [6  , 8 ,  4 ,   9 ],
#     [8  , 51,  10,  23]
# ]
#
# # 算法思路：求出每行中的最大值的 行列 坐标，求出每列最小值的 行列 坐标
# map = {}
# ans = []
# m,n = len(arr),len(arr[0])
# # 行的最大值
# for i in range(m):
#     index = 0
#     # 求出 最大值的下标索引
#     for j in range(1,n):
#         if arr[i][index] < arr[i][j]:
#             index = j
#     # 求出这一行 所有 值为 arr[i][index] 的下标索引
#     for j in range(0,n):
#         if arr[i][j] == arr[i][index]:
#             map[f'{i}{j}'] = 1
#
# # 列的最小值
# for i in range(n):
#     index = 0
#     for j in range(1,m):
#         if arr[j][i] < arr[index][i]:
#             index = j
#
#     for j in range(m):
#         if arr[j][i] == arr[index][i]:
#             if map.get(f'{j}{i}',None):
#                 ans.append([j,i])
#
# print('鞍点有：')
# for e in ans:
#     print(e,arr[e[0]][e[1]])
#
#
#
#
# # 编程实现列表进行回型初始化。（JD-II）
#
#
#
# def fun(arr):
#     ans = []
#     for e in arr:
#         ans.append(e)
#     return ans
#
#
# def fun1(arr,start,end):
#     for i in range(start,end):
#         arr[i] += 1
#
#
#
# n = int(input('输入：'))
# end = n // 2
# mid = end + (0 if n % 2 == 0 else 1)
# ans2 = []
# arr3 = [1] * n
# for i in range(n):
#     if i == 0:
#         ans2.append(arr3)
#     elif i < mid:
#         arr4 = fun(arr3)
#         fun1(arr4,i,n-i)
#         ans2.append(arr4)
#         arr3 = fun(arr4)
#     else:
#         ans2.append(ans2[end-1])
#         end -= 1
#
# for e in ans2:
#     print(e)


# 3. 有下述一个列表：（MT-II）
arr4 = [
    [1, 2, 3, 4],
    [5, 6, 7, 8],
    [9, 10, 11, 12],
    [13, 14, 15, 16],
]

# [1, 2, 3, 4],
# [5, 6, 7, 8],
# [9, 10, 11, 12],
# 和行数有关

# 1  2  3
# 4  5  6
# 7  8  9
# 10 11 12
# 和列数有关

m = len(arr4)
# 行
n = len(arr4[0])
# 列
arr5 = [[0, n - 1]]
ans = 0
v = m + n - 1
for i in range(1, v + 1):
    for e in arr5:
        print(arr4[e[0]][e[1]], end=',')

    if m <= n:
        if i <= m - 1:
            last = arr5[-1]
            addArr = []
            for e in arr5:
                addArr.append([e[0], e[1] - 1])
            addArr.append([last[0] + 1, last[1]])
            arr5 = addArr
        elif i <= v - m:
            addArr = []
            for e in arr5:
                addArr.append([e[0], e[1] - 1])
            arr5 = addArr
        else:
            arr5.pop(0)
            addArr = []
            for e in arr5:
                addArr.append([e[0], e[1] - 1])
            arr5 = addArr
    else:
        if i <= n - 1:
            last = arr5[-1]
            addArr = []
            for e in arr5:
                addArr.append([e[0], e[1] - 1])
            addArr.append([last[0] + 1, last[1]])
            arr5 = addArr
        elif i <= v - n:
            for e in arr5:
                e[0] += 1
        else:
            arr5.pop(0)
            addArr = []
            for e in arr5:
                addArr.append([e[0], e[1] - 1])
            arr5 = addArr

# 1  2  3
# 4  5  6
# 7  8  9
# 10 11 12


'''
1  2  3  4  5 
6  7  8  9  10
11 12 13 14 15

5 4 10 3 9 15 2 8 14 1 7 13 6 12 11


'''
